/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hiof.moraa.server.controller.restfulservice;

import com.hiof.moraa.server.service.LiveLocationService;
import com.hiof.moraa.server.service.model.Feed;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.hiof.moraa.server.service.model.GeoPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * @author Bergy
 */
@Controller
@RequestMapping("/restfulservice/liveLocation")
public class LiveLocationController {

    @Autowired
    LiveLocationService athleteLiveLocationService;
    @Autowired
    LiveLocationService supportLiveLocationService;

    @RequestMapping(value = "/athlete", method = RequestMethod.POST)
    @ResponseBody
    public Feed receiveAthletesLiveLocation(
            @RequestParam("userId") int userId,
            @RequestParam("athleteId") int athleteId,
            @RequestParam("lat") double lat,
            @RequestParam("lng") double lng,
            @RequestParam("high") double high, 
            @RequestParam("speed") double speed) throws Exception {
        Logger.getLogger(LiveLocationController.class.getName()).log(Level.INFO, "values:"+userId+"/"+athleteId+"/"+lat+"/"+lng+"/"+high+"/"+speed);
        return athleteLiveLocationService.updateLiveLocationFeed(userId, athleteId, lat, lng, high, speed);
    }

    @RequestMapping(value = "/support", method = RequestMethod.POST)
    @ResponseBody
    public Feed receiveSupportLiveLocation(
            @RequestParam("userId") int userId,
            @RequestParam("supportId") int supportId,
            @RequestParam("lat") double lat,
            @RequestParam("lng") double lng,
            @RequestParam("high") double high,
            @RequestParam("speed") double speed) throws Exception {
        return supportLiveLocationService.updateLiveLocationFeed(userId, supportId, lat, lng, high, speed);
    }
}
